<?php

namespace think\queue\services;

use think\App;

class queue implements \think\queue\interfaces\queue
{
    /**
     * @var App
     */
    protected $app;

    public function __construct()
    {
        $this->app = App::getInstance();
    }

    /**
     * 推送Job到队列
     * @param string $job 任务名称
     * @param array $data 任务参数
     * @param int $delay 延时
     * @param mixed $queue 目标队列
     */
    public function push(string $job, array $data, int $delay, $queue = null)
    {
        $jobClassic = ($this->app->config->get('queue.job_namespace') ?: 'job') . '\\' . trim($job);
        if (\class_exists($jobClassic)) {
            if ($delay > 0) {
                \think\facade\Queue::later($delay, $job, $data, $queue);
            } else {
                \think\facade\Queue::push($job, $data, $queue);
            }
        }
    }
}